package com.view.cn.mvprxjava.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.view.cn.mvprxjava.R;
import com.view.cn.mvprxjava.iView.UserView;
import com.view.cn.mvprxjava.presenter.UserPresenter;
import com.view.cn.mvprxjava.utils.ToastUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

//
public class UserFragment extends BaseFragment implements UserView, View.OnClickListener {

	public static final String TAG = UserFragment.class.getSimpleName();

	@Bind(R.id.tv1)
	TextView mTv1;
	@Bind(R.id.tv2)
	TextView mTv2;
	@Bind(R.id.tv3)
	TextView mTv3;
	@Bind(R.id.tv4)
	TextView mTv4;

	private UserPresenter mUserPresenter;

	public static UserFragment newInstance() {
		UserFragment fragment = new UserFragment();
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setHasOptionsMenu(true);
		mUserPresenter = new UserPresenter(this);
	}

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_user_info, container, false);

		ButterKnife.bind(this, view);
		mTv1.setOnClickListener(this);
		mTv2.setOnClickListener(this);
		mTv3.setOnClickListener(this);
		mTv4.setOnClickListener(this);
		return view;
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		ButterKnife.unbind(this);
	}

	@Override
	public void userNameError(Object... o) {
		Object[] o1 = o;
		ToastUtils.getInstance().showToast(getActivity().getApplicationContext(), "userNameError方法：" + o1[2].toString());
	}

	@Override
	public void userNameLengthError(Object... o) {
		Object[] o1 = o;
		ToastUtils.getInstance().showToast(getActivity().getApplicationContext(), "userNameLengthError方法：" + o1[2].toString());
	}

	@Override
	public void userInfoEmpty(Object... o) {
		Object[] o1 = o;
		ToastUtils.getInstance().showToast(getActivity().getApplicationContext(), "userInfoEmpty方法：" + o1[2].toString());
	}

	@Override
	public void showDialog() {
		Log.e(TAG, "弹出加载网络的对话框");
	}

	@Override
	public void hideDialog() {
		Log.e(TAG, "影藏加载网络的对话框");
	}

	@Override
	public void respense(int requestCode, String url, String data) {
		ToastUtils.getInstance().showToast(getActivity().getApplicationContext(), "respense方法：" + data);
	}

	@Override
	public void fail(int requestCode, Exception e, String data) {
		ToastUtils.getInstance().showToast(getActivity().getApplicationContext(), "fail方法：" + data);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.tv1:
				mUserPresenter.getUserInfo("zxp1234", "123456");
				break;
			case R.id.tv2:
				mUserPresenter.getUserInfo("zxp12", "123456");
				break;
			case R.id.tv3:
				mUserPresenter.getUserInfo("", "");
				break;
			case R.id.tv4:
				mUserPresenter.getUserInfo("zxp123", "123456");
				break;
		}
	}
}
